package com.qfedu.mtl.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

public class CharacterUtil {
    //处理参数|页面乱码
    public static void setUtf8(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
    }

    public static void setContentWithJson(HttpServletRequest req, HttpServletResponse resp  ) throws UnsupportedEncodingException {
        setUtf8(req, resp);
        resp.setContentType("application/json;charset=utf-8");
    }

    public static void setContentWithText(HttpServletRequest req, HttpServletResponse resp  ) throws UnsupportedEncodingException {
        setUtf8(req, resp);
        resp.setContentType("text/plain;charset=utf-8");
    }
    public static void setContentWithHtml(HttpServletRequest req, HttpServletResponse resp  ) throws UnsupportedEncodingException {
        setUtf8(req, resp);
        resp.setContentType("text/html;charset=utf-8");
    }

}
